package ch.exploadingelephants.graph;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Sandro De Zanet
 * 
 */
public class MachineGraph implements Serializable {

    private final StartToken startToken;
    private final EndToken endToken;
    private final NirvanaToken nirvanaToken;

    /**
     * 
     */
    public MachineGraph() {
	startToken = new StartToken();
	endToken = new EndToken();
	nirvanaToken = new NirvanaToken();
    }

    /**
     * @param inputPattern
     * @return
     * @throws InfinityLoopException
     */
    public TokenResult run(DotString inputPattern) throws InfinityLoopException {
	List<VisitedNodeState> visited = new ArrayList<VisitedNodeState>();
	return startToken.accept(inputPattern, visited);
    }

    /**
     * @return
     */
    public StartToken getStart() {
	return startToken;
    }

    /**
     * @return
     */
    public EndToken getEnd() {
	return endToken;
    }

    /**
     * @return
     */
    public NirvanaToken getNirvana() {
	return nirvanaToken;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
	return this.startToken.toString();
    }

}
